<template>
  <div class="cityCheck">
    <el-form :inline="true" :model="form" label-width="90px">
      <div class="maintitle">抽选工程复核单位</div>
      <div class="formcontent">
        <div class="basicInformation">
          <span>前项目级别：市级</span>
          <span>抽取时间：{{form.siphonTime}}</span>
        </div>
        <div>
          <el-form-item :label="`工程复核单位：${form.unitName}`" label-width="aout">
            <el-button
              :disabled="form.unitId ? true : false && disabled"
              size="small"
              @click="siphon"
            >抽取</el-button>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="复查单位负责人" label-width="112px">
            <el-input :disabled="disabled" v-model="form.unitPrincipal" style="width:200px;"></el-input>
          </el-form-item>
          <el-form-item label="联系电话" label-width="100px">
            <el-input :disabled="disabled" v-model="form.phone" style="width:200px;"></el-input>
          </el-form-item>
        </div>
      </div>

      <div class="maintitle" style="margin:40px 0 20px 0;">工程复核情况</div>
      <div>
        <el-form-item label="复核日期" label-width="70px">
          <el-date-picker
            :disabled="disabled"
            v-model="form.beginTime"
            type="date"
            placeholder="选择日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="至" label-width="26px">
          <el-date-picker
            :disabled="disabled"
            v-model="form.endTime"
            type="date"
            placeholder="选择日期"
          ></el-date-picker>
        </el-form-item>
      </div>
      <el-form-item label="复查人员" label-width="70px">
        <el-input :disabled="disabled" v-model="form.reviewer" style="width:400px;"></el-input>
      </el-form-item>
      <div>
        <el-form-item label="工程复核报告" label-width="98px">
          <el-upload
            v-if="!disabled"
            accept=".pdf"
            :action="uploadUrl"
            :file-list="fileList[0]"
            :on-success="handleUploadSuccess"
          >
            <el-button v-if="!disabled" size="small" type="primary">上传</el-button>
            <!-- <el-button @click="seePdf(0)" v-if="disabled" size="small" type="primary">查看</el-button> -->
          </el-upload>
          <seeFujianForList
            v-if="disabled && fileList[0]"
            @openPdf="seePdf"
            :file-obj="fileList[0]"
            :file-num="0"
          />
        </el-form-item>
      </div>
      <div class="btn">
        <el-button v-if="!disabled" type="primary" @click="addRevice">提交</el-button>
        <el-button @click="back">返回</el-button>
      </div>
    </el-form>
    <el-dialog :close-on-click-modal="false" :title="pdfName" :visible.sync="pdfFlag" width="50%">
      <div class="pdfBox">
        <iframe :src="$https + pdfUrl" style="width:100%;height:600px;" frameborder="0"></iframe>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import config from "@/config/index.js";
import {
  getReview,
  addRevice,
  siphon
} from "@/api/completionAcceptance/cityCheck.js";
import { getFile } from "@/api/completionAcceptance/acceptance";
import moment from "moment";
import seeFujianForList from "@/components/seeFujianForList";
export default {
  components: {
    seeFujianForList
  },
  data() {
    return {
      uploadUrl: config.uploadUrl,
      form: {
        flag: 1,
        projectId: localStorage.getItem("projectId"),
        unitName: ""
      },
      disabled: true,
      projectId: localStorage.getItem("projectId") || "",
      fileList: [],
      pdfUrl: "",
      pdfFlag: false,
      pdfName: ""
    };
  },

  created() {
    if (this.$route.name === localStorage.getItem("key")) {
      this.disabled = false;
    }
    if (localStorage.getItem("lookStatus") == 2) {
      this.disabled = true;
    }
    this.getReview();
  },
  methods: {
    //查看当前PDF
    seePdf(num) {
      this.pdfFlag = true;
      this.pdfUrl = this.fileList[num][0].url;
      this.pdfName = this.fileList[num][0].name;
    },
    back() {
      this.$router.push("/projectManagement/projectImplementation/dealwith");
    },
    siphon() {
      //抽取工程复核单位
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      siphon({ projectId: this.projectId })
        .then(res => {
          loading.close();
          this.form.siphonTime = res.data.siphonTime;
          this.form.unitName = res.data.unitName;
          this.form.unitId = res.data.unitId;
        })
        .catch(res => {
          loading.close();
        });
    },
    getReview() {
      //获取页面信息
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      getReview({ projectId: this.projectId })
        .then(res => {
          loading.close();
          if (res.data) {
            this.form = res.data;
            var data1 = {
              fileId: res.data.annexId
            };
            getFile(data1).then(res1 => {
              console.log(res1, "文件信息");
              this.fileList = [
                [{ name: res1.data.fileName, url: res1.data.filePath }]
              ];
            });
          }
        })
        .catch(res => {
          loading.close();
        });
    },
    handleUploadSuccess: function(res, file, fileList) {
      //工程复核报告文件上传成功回调
      this.form.annexId = res.data.id;
    },
    addRevice() {
      //提交表单
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      this.form.flag = 1;
      this.form.projectId = this.projectId;
      this.form.beginTime = moment(this.form.beginTime).format(
        "YYYY-MM-DD HH:mm:SS"
      );
      this.form.endTime = moment(this.form.endTime).format(
        "YYYY-MM-DD HH:mm:SS"
      );
      addRevice(this.form)
        .then(res => {
          loading.close();
          this.$message({
            message: "提交成功！",
            type: "success"
          });
          this.getReview();
          this.$router.push(
            "/projectManagement/projectImplementation/dealwith"
          );
        })
        .catch(res => {
          loading.close();
        });
    }
  }
};
</script>

<style lang="scss" scoped>
.cityCheck {
  padding: 20px 20px 0 20px;
  min-height: calc(100vh - 154px);
  background-color: #fff;
  .maintitle {
    font-size: 18px;
    font-family: PingFang SC;
    font-weight: bold;
    line-height: 25px;
    color: #4d4d4d;
  }
  .formcontent {
    margin-top: 30px;
    .basicInformation {
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 500;
      line-height: 20px;
      color: #8c8c8c;
      margin-bottom: 20px;
      span {
        margin-right: 60px;
      }
    }
    .basicInformationitem {
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 500;
      line-height: 20px;
      color: #8c8c8c;
      float: left;
      width: 251px;
      margin-bottom: 20px;
    }
  }
}
</style>
<style lang="scss" scoped>
/deep/ .el-form--inline .el-form-item__label {
  color: #a1a1a1;
}

.btn {
  margin-top: 30px;
}
</style>